//
//  WBNavigationViewController.swift
//  微博
//
//  Created by WangQiang on 2017/8/29.
//  Copyright © 2017年 WangQiang. All rights reserved.
//

import UIKit

class WBMainNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden = true
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            if let vc =  viewController  as?  WBBaseViewController {
                var title = "返回"
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem.init(backTitle: title, target: self, action: #selector(popToParent))
            }
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc fileprivate func popToParent() {
        popViewController(animated: true)
    }
}
